<?php
session_start();
require 'openid.php';
try {
    $openid = new LightOpenID;
    if(!$openid->mode) {
    
            $openid->identity = 'https://www.google.com/accounts/o8/id?openid.mode=checkid_immediate';
			$openid->required = array('namePerson/first', 'namePerson/last', 'contact/email');
            header('Location: ' . $openid->authUrl());
     
    } elseif($openid->mode == 'cancel') {
        echo 'Usuario ha cancelado la autenticacion!';
    } else {
       // echo 'Usuario ' . ($openid->validate() ? $openid->identity . ' has ' : 'no ha') . 'iniciado sesion.';
		//echo 'Usuario <b>' . $openid->identity . '</b> se ha logueado.<br>';

			//echo "<h3>Informacion</h3>";

			$identity = $openid->identity;
			$attributes = $openid->getAttributes();
			$email = $attributes['contact/email'];
			$first_name = $attributes['namePerson/first'];
			$last_name = $attributes['namePerson/last'];

			/*echo "modo: " . $openid->mode . "<br>";
			echo "identidad: " . $identity . "<br>";
			echo "correo: " . $email . "<br>";
			echo "primer nombre: " . $first_name . "<br>";
			echo "segundo nombre: " . $last_name . "<br>";*/
			//echo "aqui nosotros tenemos el control";
			
			$_SESSION['usuario']=$first_name." ".$last_name;
               $rurl = "http://localhost/envios";
              //header("Location:$rurl");   
			   //document.location="http://localhost/envios/index.php?id=<?=$_SESSION['usuario'];  ?>
			  <script>
			  document.location="http://localhost/envioscake/index.php?id=<?=$_SESSION['usuario'];?>";
			  </script>
   <? }
} catch(ErrorException $e) {
    echo $e->getMessage();
}
